#include <stdio.h>
#include <time.H>
#include <assert.h>
#include <windows.h>

DWORD WINAPI thread_t1(LPVOID para) {
	srand(time(0));
	while (WaitForSingleObject(para, 1) != WAIT_OBJECT_0) {
		printf("%d, ", rand() % 100);
	}
	return 0;
}

int main(int argc, char* argv[]) {
	HANDLE hEvent, hThread;

	hEvent = CreateEvent(0, 1, 0, 0);
	assert(hEvent);

	hThread = _beginthreadex(0, 0, thread_t1, hEvent, 0, 0);
	assert(hThread);

	getchar();
	SetEvent(hEvent);
	CloseHandle(hEvent);

	WaitForSingleObject(hThread, INFINITE);
	CloseHandle(hThread);
	return 0;
}
